package com.baozheyangken.ai_learn.controller;

import com.baozheyangken.ai_learn.annotation.RequiresAuthentication;
import com.baozheyangken.ai_learn.pojo.entity.Question;
import com.baozheyangken.ai_learn.pojo.result.Result;
import com.baozheyangken.ai_learn.service.PracticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/practice")
@Slf4j
@RequiresAuthentication
public class PracticeController {

    @Autowired
    private PracticeService practiceService;

    /**
     * 获取练习题目
     * @param params 查询参数（typeId, difficultyId, keyword等）
     * @return 题目列表
     */
    @PostMapping("/questions")
    public Result<List<Question>> getQuestions(@RequestBody Map<String, Object> params) {
        try {
            log.info("获取练习题目请求，参数: {}", params);
            List<Question> questions = practiceService.getQuestions(params);
            return Result.success(questions);
        } catch (Exception e) {
            log.error("获取练习题目失败: {}", e.getMessage(), e);
            return Result.error("获取题目失败: " + e.getMessage());
        }
    }

    /**
     * 智能测试（待实现）
     * @param params 测试参数
     * @return 测试题目
     */
    @PostMapping("/intelligent-test")
    public Result<List<Question>> intelligentTest(@RequestBody Map<String, Object> params) {
        try {
            log.info("智能测试请求，参数: {}", params);
            List<Question> questions = practiceService.IntelligentTest(params);
            return Result.success(questions);
        } catch (Exception e) {
            log.error("智能测试失败: {}", e.getMessage(), e);
            return Result.error("智能测试生成失败");
        }
    }
}
